package thread;

/**
 * @Author liangzai
 * @Description:
 */
class MyRunnable implements Runnable {
    // 2. 实现run方法，这里写线程要执行的任务逻辑
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("线程 " + Thread.currentThread().getName() + " 执行，i = " + i);
        }
    }
}


public class ThreadExample2 {
        public static void main(String[] args) {
            // 3. 创建实现了Runnable接口的类的对象
            MyRunnable myRunnable = new MyRunnable();
            // 4. 创建Thread对象，将实现Runnable接口的对象作为参数传入
            Thread thread = new Thread(myRunnable);
            // 5. 启动线程
            thread.start();

            // 主线程执行的其他操作示例
            for (int i = 0; i < 5; i++) {
                System.out.println("主线程执行，i = " + i);
            }
        }

}
